<?php
include_once '../header1.php';
?>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","upp_sch_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{
document.DelCom.SchName.value=val;
document.getElementById("List").innerHTML="";
var xmlhttp;    
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("CompId").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","CIDupp.php?q="+val,true);
xmlhttp.send();
}
</script>
<script type="text/javascript">
function getComDate(com)
{
var xmlhttp;  
var sch=document.forms["DelCom"]["SchName"].value;
var hin=com+","+sch; 
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("Com_date").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_Com_date.php?q="+hin,true);
xmlhttp.send();
}
</script>
<script type="text/javascript">
function DeleteVerification()
{
<?php
include_once ("../login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
   
   else
   {
   ?>   
var Competition_Name=document.forms["DelCom"]["Competition_Name"].value;
var School_Id=document.forms["DelCom"]["SchName"].value;
var Date=document.forms["DelCom"]["Date"].value;
if (Competition_Name=="Select One"||Date=="Select One"||School_Id=="")
  {
  alert("Please select the Competition Id,School Id and Date to delete!");
  return false;
  }
  
if (Competition_Name!="Select One"&&Date!="Select One"&&School_Id!="")
{
var r=confirm("Are you sure to delete this?");
if (r==true)
  {
  return true;
 
 }

if(r==false)
  {
 return false;
  }
}
}
</script>
</head>
<body>
 
<?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?><div id="content">
	<div id="main">
	  <div id="bodyfield">
      <div id="lefttablereg">
<form name="DelCom" action="#" method="POST" onSubmit="return DeleteVerification()">
<?php
if(isset($_POST['Delete']))
{
require_once 'DEL.php';
}
?>
  <table width="541" border="0" class="tablefontv">
    <tr>
      <td height="18" colspan="5"  scope="row"  class="err">
      <?php
      if(isset($_POST['Delete']))
{
	if(isset($_SESSION['errorin']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['error']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['error'];
		unset($_SESSION['error']);
	}
	if(isset($_SESSION['errornorow']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
	if(isset($_SESSION['errornot']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornot'];
		unset($_SESSION['errornot']);
	}
	if(isset($_SESSION['errornot2']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornot2'];
		unset($_SESSION['errornot2']);
	}
}   
?>
</td>
      </tr>
    <tr>
      <th width="40" height="24"  scope="row" bgcolor="#6AB5FF">&nbsp;</th>
      <td width="110" height="24"  scope="row" bgcolor="#6AB5FF">School's Name</td>
      <td width="140" bgcolor="#999999"> 
	     <?php
	 	if($_SESSION['Access_Type']=="Teacher in Charge")
{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id']; 
    $snam=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
}
	 echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' size='40' readonly='readonly'/>";
}
	else if($_SESSION['Access_Type']=="Administrator")
{
	if(!isset($SchName))
	{
		$snam=mysql_query("SELECT * FROM school WHERE School_Id='$School_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
	}
	    echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' size='40'/>";
}
	  ?>
	  </td>
      <td width="84" bgcolor="#6AB5FF">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <th height="26" scope="row" bgcolor="#6AB5FF">&nbsp;</th>
      <td height="26" scope="row" bgcolor="#6AB5FF">Competition Name:</td>
      <td bgcolor="#999999">
	  <div id="CompId">
	  <select name="Competition_Name" id="Competition_Name" onChange="getComDate(this.value)">
        <?php
	 if(isset($_POST['Delete']))
	  {
	   $resultnet=mysql_query("SELECT * FROM competitions WHERE Programme_Id='$Competition_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Competition_Name=$rownet['Competition_Name'];
}
	 		 echo '<option value="'.$Competition_Name.'">'.$Competition_Name.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  		if($School_Id!="")
		{
			$com=mysql_query("SELECT DISTINCT(Competition_Id) FROM competition WHERE School_Id='$School_Id'");
		}
		if($School_Id=="")
		{
	  $com=mysql_query("SELECT DISTINCT(Competition_Id) FROM competition");
		}
	  
  while($row=mysql_fetch_array($com))
  {
	 $Compe_Id=$row['Competition_Id'];
	 $resultnet=mysql_query("SELECT * FROM competitions WHERE Competition_Id='$Compe_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Compe_Name=$rownet['Competition_Name'];
}
if($Competition_Name!=$Compe_Name)
{
	  echo '<option value="'.$Compe_Name.'">'.$Compe_Name.'</option>';
}
  }
 
	  ?>
      </select></div></td>
      <td bgcolor="#6AB5FF">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <th height="23" scope="row" bgcolor="#6AB5FF">&nbsp;</th>
      <td scope="row" bgcolor="#6AB5FF">Date:</td>
      <td bgcolor="#999999">
	  <div id="Com_date"><select name="Date" id="select">
	 <?php
	  
	  if(isset($_POST['Delete']))
	  {
	 echo '<option value="'.$Date.'">'.$Date.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	  $com=mysql_query("SELECT DISTINCT(Date) FROM competition");
	  
  while($row=mysql_fetch_array($com))
  {
	 $Dat=$row['Date'];
if($Date!=$Dat)
{
	  echo '<option value="'.$Dat.'">'.$Dat.'</option>';
  }
  }
	 ?>
      </select></div></td>
      <td bgcolor="#6AB5FF">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <th height="23" scope="row" bgcolor="#6AB5FF">&nbsp;</th>
      <th colspan="3" scope="row" bgcolor="#6AB5FF"><a href="DelCom.php" class="reset">Reset |</a>
        <input name="Delete" align="middle" type="submit" value="Delete" class="buttonok"/></th>
      <td width="145">&nbsp;</td>
    </tr>
  </table>

  <br/>
  <br/>
   </form>
  <?php
   	   if(isset($_POST['Delete']))
{
	if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
   {
		if($Competition_Id!=""&&$School_Id!=""&&$Date!=""&&$No_Of_Students!="")
  { 
    echo '<table width="458" border="0" class="tablefontv">';
    echo '<tr>';
        echo '<th width="200" height="44" scope="row" >';
		echo "Competition Id:";
		echo '</th>';
        echo '<td width="144">';
		echo $Competition_Id;
		echo '</td>';
      echo '</tr>';
       echo '<tr>';
        echo '<th width="200" height="44" scope="row" >';
		echo "Competition Name:";
		echo '</th>';
        echo '<td width="144">';
		echo $Competition_Name;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number of students:";
		echo '</th>';
        echo '<td>';
		echo $No_Of_Students;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number of teachers:";
		echo '</th>';
        echo '<td>';
		echo $No_Of_Teachers;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Result:";
		echo '</th>';
       echo '<td>';
	   echo $Result;
	   echo '</td>';
      echo '</tr>';
        echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Scope:"; 
		echo '</th>';
        echo '<td>';
		echo $Scope;
		echo '</td>';
      echo '</tr>';
	  if($Result=="Win")
	  {
	   echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Winner:"; 
		echo '</th>';
        echo '<td>';
		echo $Winner;
		echo '</td>';
      echo '</tr>';
	  }
	 
   }
    echo '</table>';
	
	}
}	
    ?>
	 </div>
<div id="righttablereg">
  <div class="suggestionListsch" id="List"></div>
 </div>
	</div>
	</div>
</div>
<div id="sidebar"><br/>
<div id="partners" class="boxed">
			<h2 class="title">COMPETITIONS</h2>
            </div>
<?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
?>
<?php
	  }
?>
</body>
</html>